import { url } from "./config.js"
import {cookie} from "../../static/javascripts/cookie.js"
$(document).ready(function () {
    $("a").on("click",function(e){
        e.preventDefault();
    })
    //三角旋转动画
    // console.log($('.add_after'));
    $(".add_after").hover(
        function () {
            // console.log($(this.children[0].children.));
            // $(this.children[0].children[0]).addClass("nav_sanjia_active");
            $(this).find(".nav_sanjiao").rotate({ animateTo: 180, duration: 500 });
            // console.log($(this).find(".nav_sanjiao"));            
        },
        function () {
            $(this).find(".nav_sanjiao").rotate({ animateTo: 0, duration: 500 });

        }
    )
    //导航栏二级菜单
    $("#classes li").mouseover(async function () {
        // console.log($(this).attr("data-index"));
        let data_index = $(this).attr("data-index");
        let data = await getSecondMenuData(data_index);
        // console.log(data);
        // console.log($(".second_menu"));
        $(".second_menu").find(".part1 .minibox:first p").html(data.part1.title)
        let strP1 = "";
        for (let i = 0; i < data.part1.datas.length; i++) {
            strP1 += "<a>" + data.part1.datas[i] + "</a>"
        }
        $(".second_menu").find(".part1 .minibox:first .item").html(strP1)
        $(".second_menu").find(".part1 .minibox:last p").html(data.part2.title)
        let strP2 = "";
        for (let i = 0; i < data.part2.datas.length; i++) {
            strP2 += "<a>" + data.part2.datas[i] + "</a>"
        }
        $(".second_menu").find(".part1 .minibox:last .item").html(strP2)
        $(".second_menu").find(".part2 .minibox:first p").html(data.part3.title)
        let strP3 = "";
        for (let i = 0; i < data.part3.datas.length; i++) {
            strP3 += "<a>" + data.part3.datas[i] + "</a>"
        }
        $(".second_menu").find(".part2 .minibox:first .item").html(strP3)
        $(".second_menu").find(".part2 .minibox:last p").html(data.part4.title)
        let strP4 = "";
        for (let i = 0; i < data.part4.datas.length; i++) {
            strP4 += "<a>" + data.part4.datas[i] + "</a>"
        }
        $(".second_menu").find(".part2 .minibox:last .item").html(strP4)

        $(".second_menu").find(".part3 .minibox:first p").html(data.part5.title)
        let strP5 = "";
        for (let i = 0; i < data.part5.datas.length; i++) {
            strP5 += "<a>" + data.part5.datas[i] + "</a>"
        }
        $(".second_menu").find(".part3 .minibox:first .item").html(strP5)

        $(".second_menu").find(".part3 .minibox:last p").html(data.part6.title)
        let strP6 = "";
        for (let i = 0; i < data.part6.datas.length; i++) {
            strP6 += "<a>" + data.part6.datas[i] + "</a>"
        }
        $(".second_menu").find(".part3 .minibox:last .item").html(strP6)


        $(".second_menu").find(".imgbox img").each(function (i) {
            // console.log("img",data.images[i]);
            this.src = data.images[i].src;
        })


        $(".second_menu").find(".remai img").attr("src", data.class.scr);

    })
    //所有分类点击效果
    let class_isShow = false;
    //点击所有分类按钮
    $("#all_classBtn").on("click",function () {
        class_isShow = !class_isShow;
        showAllClass();
    })
    //判断是否显示所有分类菜单classes
    //初始化隐藏
    $("#classes").hide();
    function showAllClass() {
        if (class_isShow) {
            $("#classes").show();
        } else {
            $("#classes").hide();
        }
    }

    $(".shop_car").on("click",function(){
        if(checkLogin()){
            location.href=`../../dist/shopCar.html`
        }
    });
    function checkLogin() {
        let TOKEN = cookie("TOKEN");
        if (TOKEN === null || TOKEN === undefined || TOKEN === "") {
              console.log(11);
              $("#login").trigger("click");
        } else {
              return true;
        }
  }
    $(".nav2").find("li:first-child").on("click",function(){
        console.log(1);
        location.href=`../../dist/index.html`
    })
    
    //获取二级菜单数据
    async function getSecondMenuData(index) {
        let load = axios.create({
            baseURL: url
        })
        // console.log(url);
        let options = {
            url: "/second_menu.json"
        };
        let res = await load(options);
        // console.log(res.data[index]);
        let data = res.data[index]
        return data;
    }


})